<template>
    <div class="message-list">
      <div class="message-list-block">
        <div class="message-list-header">
          <span class="ms-title">我的消息</span>
          <span class="message-list-back" @click="goBack()">返回</span>
        </div>
        <div class="mesage-list-content" v-for="(item, index) in messageList" :key="index">
          <img src="@/assets/message/notice.png" width="50px" class="image" />
          <div class="message-content">
            <div class="title-box">
              <div class="title">
                {{ item.messageTitle }}
              </div>
            </div>
            <div class="content">{{ item.messageContent }}</div>
          </div>
          <el-button class="mesage-button" type="text" @click.stop="handlerDelete(item)">删除</el-button>
        </div>
        <div class="message-pagination">
          <!-- 增加分页展示器 -->
          <el-pagination background layout="total, sizes, prev, pager, next, jumper" :total="total"
            v-model:current-page="params.pageNum" v-model:page-size="params.pageSize" :page-sizes="[5, 10, 15, 20]"
            @size-change="handleSizeChange" @current-change="handleCurrentChange" />
        </div>
      </div>
    </div>
  </template>
  
  <script setup>
  import { getMessageListService } from "@/apis/message"
  import router from "@/router"
  import { reactive, ref } from "vue"
  
  const messageList = ref([]) //消息列表
  
  const total = ref(0)
  const params = reactive({
    pageNum: 1,
    pageSize: 10,
  })
  
  //消息列表
  async function getMessageList() {
    const ref = await getMessageListService(params)
    messageList.value = ref.rows
    total.value = ref.total
  }
  getMessageList()
  
  const goBack = () => {
    router.go(-1)
  }
  // 分页
  function handleSizeChange(newSize) {
    params.pageNum = 1
    getMessageList()
  }
  
  function handleCurrentChange(newPage) {
    getMessageList()
  }
  </script>
  
  <style lang="scss" scoped>
  .message-list {
    background-color: #f8fafc;
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    min-height: calc(100vh - 64px);
    padding: 24px;
    animation: fadeIn 0.5s ease-out;
  
    .message-list-block {
      margin: 0 auto;
      width: 100%;
      max-width: 1200px;
      background: #fff;
      border-radius: 16px;
      box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
      padding: 24px;
      transition: all 0.3s ease;
  
      &:hover {
        box-shadow: 0 8px 16px -4px rgba(0, 0, 0, 0.1);
      }
  
      .message-pagination {
        margin: 24px 0 0;
        display: flex;
        justify-content: center;
      }
  
      .message-list-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 24px;
        border-bottom: 1px solid #e2e8f0;
        margin-bottom: 24px;
  
        .ms-title {
          font-family: PingFangSC, PingFang SC;
          font-weight: 600;
          font-size: 24px;
          color: #1e293b;
          position: relative;
          padding-left: 16px;
  
          &::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 20px;
            background: linear-gradient(135deg, #32C5FF 0%, #3EC8FF 100%);
            border-radius: 2px;
          }
        }
  
        .message-list-back {
          cursor: pointer;
          color: #64748b;
          font-size: 14px;
          padding: 8px 16px;
          border-radius: 8px;
          transition: all 0.3s ease;
  
          &:hover {
            color: #32C5FF;
            background: #f1f5f9;
            transform: translateX(-4px);
          }
        }
      }
  
      .mesage-list-content {
        background: #fff;
        border-radius: 12px;
        margin-bottom: 16px;
        padding: 20px;
        display: flex;
        align-items: center;
        transition: all 0.3s ease;
        animation: slideIn 0.5s ease-out;
        position: relative;
        overflow: hidden;
  
        &:hover {
          transform: translateY(-2px);
          box-shadow: 0 8px 16px -4px rgba(0, 0, 0, 0.1);
        }
  
        &::before {
          content: '';
          position: absolute;
          left: 0;
          top: 0;
          height: 100%;
          width: 4px;
          background: linear-gradient(135deg, #32C5FF 0%, #3EC8FF 100%);
          border-radius: 0 2px 2px 0;
        }
  
        .image {
          width: 48px;
          height: 48px;
          border-radius: 12px;
          margin-right: 20px;
          transition: all 0.3s ease;
  
          &:hover {
            transform: scale(1.1);
          }
        }
  
        .message-content {
          flex: 1;
          margin-right: 20px;
  
          .title-box {
            margin-bottom: 8px;
  
            .title {
              font-family: PingFangSC, PingFang SC;
              font-weight: 600;
              font-size: 16px;
              color: #1e293b;
              line-height: 1.4;
            }
          }
  
          .content {
            font-family: PingFangSC, PingFang SC;
            font-weight: 400;
            font-size: 14px;
            color: #64748b;
            line-height: 1.5;
          }
        }
  
        .mesage-button {
          width: 80px;
          height: 40px;
          background: #f1f5f9;
          border-radius: 20px;
          color: #64748b;
          font-size: 14px;
          transition: all 0.3s ease;
  
          &:hover {
            background: #32C5FF;
            color: #fff;
            transform: translateY(-2px);
            box-shadow: 0 4px 6px -1px rgba(50, 197, 255, 0.2);
          }
        }
      }
    }
  }
  
  @keyframes fadeIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }
  
  @keyframes slideIn {
    from {
      transform: translateX(-20px);
      opacity: 0;
    }
    to {
      transform: translateX(0);
      opacity: 1;
    }
  }
  </style>